package io.xxx.omni.oss.common

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import okhttp3.OkHttpClient
import java.text.DecimalFormat
import java.text.NumberFormat
import java.text.SimpleDateFormat
import java.time.Duration
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit

val gson: Gson = GsonBuilder()
    .setDateFormat("yyyy-MM-dd HH:mm:ss")
    .create()

val client = OkHttpClient.Builder()
    .readTimeout(Duration.ofSeconds(0))
    .build()

private val processors = Runtime.getRuntime().availableProcessors()

val pool = ThreadPoolExecutor(
    processors, 4 * processors,
    120, TimeUnit.SECONDS,
    ArrayBlockingQueue(32),
    ThreadPoolExecutor.CallerRunsPolicy()
)

val numberFormat: NumberFormat = DecimalFormat("#,##0.00")

val zoneOffset: ZoneOffset = OffsetDateTime.now().offset

const val dateTimeFormatPattern = "yyyy-MM-dd HH:mm:ss"

val dateTimeFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern(dateTimeFormatPattern)

val dateFormat = SimpleDateFormat(dateTimeFormatPattern)
